package cn.edu.lzu.dao;

import cn.edu.lzu.entity.Examiner;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.List;

/**
 * @PackageName: cn.edu.lzu.dao
 * @InterfaceName: ExaminerMapper
 * @Description: TODO
 * @Author: 张琦[QQ:3098086691]
 * @Date: 2019/11/28 16:48
 * @Version: 1.0
 */
@Mapper
public interface ExaminerMapper {
    @Insert("insert into examiner (examiner_id, password, unit_id, registe_time, examiner_name, status, is_deleted) values(#{examinerId}, #{password}, #{unitId}, #{registeTime}, #{examinerName}, #{status}, 0)")
    int insExaminer(Examiner examiner);

    @Insert("insert into examiner (examiner_id, password, examiner_name, office, duty, professional_title_id, id_number, nation_id, telephone, email, address, picture, description, degree, school, faith, politic_status, unit_id, status, is_deleted) values(#{examinerId}, #{password}, #{examinerName}, #{office}, #{duty}, #{professionalTitleId}, #{idNumber}, #{nationId}, #{telephone}, #{email}, #{address}, #{picture}, #{description}, #{degree}, #{school}, #{faith}, #{politicStatus}, #{unitId}, #{status}, 0)")
    int insNewExaminer(Examiner examiner);

    @Select("select * from examiner where examiner_id = #{examinerId} and is_deleted=0")
    Examiner selExaminerById(long examinerId);

    @Select("select * from examiner where examiner_id=#{examinerId}")
    Examiner selExaminerByIdFromAll(long examinerId);

    @Update("update examiner set last_login_time = now() where examiner_id = #{examinerId} ")
    int updExaminerLastLoginTime(long examinerId);

    @Select("select * from examiner where unit_id=#{unitId} and is_deleted=0 limit #{startIndex}, #{pageSize}")
    List<Examiner> selPageExaminer(int startIndex, int pageSize, long unitId);

    //所属某一单位的员工总数
    @Select("select count(*) from examiner where unit_id=#{unitId} and is_deleted=0")
    int selCountOfUnit(long unitId);

    @Select("select max(examiner_id) from examiner where unit_id=#{unitId}")
    long selMaxExaminerIdOfUnit(long unitId);

    @Update("update examiner set status = #{status} where examiner_id = #{examinerId} ")
    int updExaminerStatus(long examinerId, boolean status);

    @Update("update examiner set status = 1 where examiner_id in (${examinerIds})")
    int updBatchExaminerStatusToTrue(String examinerIds);

    @Update("update examiner set status = 0 where examiner_id in (${examinerIds})")
    int updBatchExaminerStatusToFalse(String examinerIds);

    @Update("update examiner set is_deleted = 1 where examiner_id in (${examinerIds})")
    int updBatchDeleteExaminers(String examinerIds);

    @Update("update examiner set is_deleted = 1 where examiner_id = #{examinerId}")
    int updDeleteExaminerByExaminerId(long examinerId);

    @Select("select * from examiner where unit_id=#{unitId} and is_deleted=0 and examiner_id like concat('%', ${examinerId}, '%') limit 0, #{pageSize}")
    List<Examiner> selFuzzySearchExaminersByExaminerId(long unitId, int pageSize, String examinerId);

    @Select("select count(*) from examiner where unit_id=#{unitId} and is_deleted=0 and examiner_id like concat('%', ${examinerId}, '%')")
    int selCountExaminerByFuzzySearch(long unitId, String examinerId);

    @Update("update examiner set password=#{newPassword} where examiner_id=#{examinerId}")
    int updPassowrdByExaminerId(String newPassword, long examinerId);

    @Select("select * from examiner where examiner_name=#{examinerName} and id_number=#{idNumber}")
    Examiner selUserByIdNumberAndName(String examinerName, String userIdentity);

    @Select("select * from examiner where is_deleted=0 and unit_id=#{unitId}")
    List<Examiner> selExaminersByUnitId(long unitId);
}
